package support

import (
	"freechat-im/common"
	"freechat-im/config"
	"github.com/samuel/go-zookeeper/zk"
	"github.com/sirupsen/logrus"
)

// RegisterNode 注册NodeName
func RegisterNode() {
	//保证有root节点（持久节点）
	config.GetZkConn().Create(common.NodeActivePath, nil, 0, zk.WorldACL(zk.PermAll))

	//将NodeName注册到zookeeper中（临时节点）
	_, err := config.GetZkConn().Create(common.NodeActivePath+"/"+common.NodeName, nil, 1, zk.WorldACL(zk.PermAll))
	if err != nil {
		logrus.Error("Node ("+common.NodeName+")注册到zookeeper中出错，", err)
	} else {
		logrus.Info("Node (" + common.NodeName + ")已注册到zookeeper中")
	}
}
